package com.zat.mes.andrmes.dofun.work.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.OrderCraftprocessBean

/**
 * @author zy
 * @date :2020-03-23 11:07
 * @description:做工工序 dialog adapter
 */
class WorkRecordProcAdapter(context: Context, list: MutableList<OrderCraftprocessBean>) :
    BaseAdapter() {
    val context = context
    val dataList: MutableList<OrderCraftprocessBean>? = list
    var selectPosition = 0
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var viewHolder: ViewHolder? = null
        var view: View? = null
        if (convertView == null) {
            viewHolder = ViewHolder()
            view = LayoutInflater.from(context).inflate(R.layout.item_work_record_proc, null)
            viewHolder.textView = view.findViewById(R.id.work_record_proc_item)
            viewHolder.imageView = view.findViewById(R.id.ivSelectWorkProc)
            view.tag = viewHolder
        } else {
            view = convertView
            viewHolder = view.tag as ViewHolder
        }

        viewHolder.textView?.text = dataList?.get(position)?.procName
        if (position == selectPosition) {
            viewHolder.imageView?.visibility = View.VISIBLE
        } else {
            viewHolder.imageView?.visibility = View.GONE
        }

        viewHolder.textView?.setOnClickListener {
            selectPosition = position;
            notifyDataSetChanged()
        }
        return view!!
    }

    override fun getItem(position: Int): OrderCraftprocessBean? {
        return dataList?.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return dataList?.size!!
    }

    class ViewHolder {
        var textView: TextView? = null
        var imageView: ImageView? = null
    }

}